package com.yserp.project.erp.bill.receivemoney.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.bill.receivemoney.domain.ReceiveMoney;
import com.yserp.project.erp.bill.receivemoney.domain.ReceiveMoneyDto;
import com.yserp.project.erp.bill.receivemoney.domain.ReceiveMoneyVo;
import com.yserp.project.erp.bill.receivemoney.service.IReceiveMoneyService;
import com.yserp.project.erp.common.enums.OrderEnums;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 收款单Controller
 * 
 * @author yserp
 * @date 2022-08-11
 */
@Controller
@RequestMapping("/bill/receivemoney")
public class ReceiveMoneyController extends BaseController
{
    private String prefix = "erp/bill/receivemoney";

    @Autowired
    private IReceiveMoneyService receiveMoneyService;

    @RequiresPermissions("bill:receivemoney:view")
    @GetMapping()
    public String receivemoney()
    {
        return prefix + "/receivemoney";
    }

    /**
     * 查询收款单列表
     */
    @RequiresPermissions("bill:receivemoney:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReceiveMoney receiveMoney)
    {
        startPage();
        List<ReceiveMoney> list = receiveMoneyService.selectReceiveMoneyList(receiveMoney);
        return getDataTable(list);
    }

    /**
     * 导出收款单列表
     */
    @RequiresPermissions("bill:receivemoney:export")
    @Log(title = "收款单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReceiveMoney receiveMoney)
    {
        List<ReceiveMoney> list = receiveMoneyService.selectReceiveMoneyList(receiveMoney);
        ExcelUtil<ReceiveMoney> util = new ExcelUtil<ReceiveMoney>(ReceiveMoney.class);
        return util.exportExcel(list, "收款单数据");
    }

    /**
     * 新增收款单
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("receiveMoneyOrderCode", OrderEnums.getCacheOrderNo(OrderEnums.RECEIVE_MONEY.getPref()));
        return prefix + "/add";
    }

    /**
     * 新增保存收款单
     */
    @RequiresPermissions("bill:receivemoney:add")
    @Log(title = "收款单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReceiveMoneyDto receiveMoney)
    {
        return toAjax(receiveMoneyService.insertReceiveMoney(receiveMoney));
    }

    /**
     * 修改收款单
     */
    @RequiresPermissions("bill:receivemoney:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ReceiveMoneyVo receiveMoney = receiveMoneyService.selectReceiveMoneyById(id);
        mmap.put("receiveMoneyVo", receiveMoney);
        return prefix + "/edit";
    }

    /**
     * 修改保存收款单
     */
    @RequiresPermissions("bill:receivemoney:edit")
    @Log(title = "收款单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReceiveMoneyDto receiveMoney)
    {
        return toAjax(receiveMoneyService.updateReceiveMoney(receiveMoney));
    }

    /**
     * 删除收款单
     */
    @RequiresPermissions("bill:receivemoney:remove")
    @Log(title = "收款单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(receiveMoneyService.deleteReceiveMoneyByIds(ids));
    }

    /**
     * 审核付款单
     */
    @RequiresPermissions("bill:receivemoney:audit")
    @Log(title = "付款单", businessType = BusinessType.AUDIT)
    @PostMapping("/audit")
    @ResponseBody
    public AjaxResult audit(String ids) {
        return toAjax(receiveMoneyService.auditReceiveMoneyByIds(ids));
    }
}
